<template>
  <div class="
    white-module">
    <div class="scholl-tabs">
      <el-tabs v-model="activeName">
        <el-tab-pane label="老师列表" name="first"></el-tab-pane>
      </el-tabs>
    </div>
    <el-row class="search-module" >
      <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()" style="width: 100%">
        <el-col class="search-left" :span="18">
          老师账号：<el-input  v-model="dataForm.like_account" placeholder="请输入老师账号" />
          <span class="interval"></span>
        </el-col>
        <el-col class="right-btn" :span="6">
          <el-button type="primary"  @click="getDataList()" >查询</el-button>
          <el-button type="default" @click="clearForm()">重置</el-button>
        </el-col>
      </el-form>
    </el-row>
    <div class="global-table">
      <el-table
          :data="dataList"
          :header-cell-style="{
          background: '#F5F7FA',
          color: '#333',
        }"
          style="width: 100%"
      >
        <el-table-column prop="account" label="老师账号" />
        <el-table-column prop="schoolName" label="所属学校" />
        <el-table-column label="操作" width="180">
          <template #default="scope">
            <el-button type="text" size="small" @click="showResetPassDialog(scope.row.id)"> 重置密码 </el-button>
            <!--<el-button type="text" size="small" @click="showUpdateDialog(scope.row.id)"> 修改信息 </el-button>-->
          </template>
        </el-table-column>
      </el-table>
    </div>

    <el-row class="global-pagination" >
      <el-col :span="8" class="total"> 共搜索 {{total}} 条数据 </el-col>
      <el-col :span="16">
        <el-pagination
            background
            layout="  prev, pager, next, jumper"
            :current-page="page"  :page-sizes="[10, 20, 50, 100]" :page-size="limit"
            :total="total"
            :small="false"
            :disabled="false"
            @size-change="query"
            @current-change="pageCurrentChangeHandle"
        />
      </el-col>
    </el-row>

    <el-dialog title="重置密码" v-model="showResetPass">
      <el-form :model="resetPassForm">
        <el-form-item label="输入新密码" :label-width="formLabelWidth">
          <el-input v-model="resetPassForm.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="再次输入密码" :label-width="formLabelWidth">
          <el-input v-model="resetPassForm.password2" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="showResetPass = false">取 消</el-button>
        <el-button type="primary" @click="resetPass">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="修改信息" v-model="showUpdate">
      <el-form :model="editForm">
        <el-form-item label="选择学校" :label-width="formLabelWidth">
          <el-select class="m-2" v-model="editForm.schoolId" placeholder="选择学校">
            <el-option v-for="item in schoolList" :label="item.schoolName" :value="item.id" :key="item.id"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="showUpdate = false">取 消</el-button>
        <el-button type="primary" @click="editTeacher">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>


<script lang="ts" >
import { defineComponent, reactive, toRefs,ref } from "vue";
import listService from "@/service/listService";
import {ElMessage} from "element-plus";
import baseService from "@/service/baseService";

export default defineComponent({
  setup() {


    const state = reactive({
      getDataListURL: "/fii/front/account/page",
      getDataListIsPage: true,
      deleteURL: "/pay/order",
      isNavCollapse:true,
      activeName:"first",
      deleteIsBatch: true,
      dataForm: {
        orderId: "",
        eq_type: "3",
        like_account: ""
      }
    });
    return { ...listService(state), ...toRefs(state) };
  },

  data() {
    return {
      showResetPass: false,
      showUpdate: false,
      resetPassForm: {
        id: null,
        password: '',
        password2: ''
      },
      editForm:{
        id: null,
        schoolId: ''
      },
      formLabelWidth: '120px',
      schoolList: []
    };
  },

  methods: {
    payHandle(orderId: string) {
      //window.open(`${app.api}/pay/alipay/webPay?orderId=` + orderId);
    },

    clearForm(){
      this.dataForm.like_account = '';
    },

    showResetPassDialog(id: any){
      this.showResetPass = true;
      this.resetPassForm.id = id;
    },

    showUpdateDialog(id: any){
      this.showUpdate = true;
      this.editForm.id = id;
      this.querySchool();
    },

    /**
     * 查询学校
     */
    querySchool(){
      baseService
          .get("/fii/front/school/page", {})
          .then((res) => {
                if (res.code === 0) {
                  this.schoolList = res.data.list;
                }
              }
          );
    },

    /**
     * 修改学校
     */
    editTeacher(){
      baseService
          .post("/fii/front/account/editName", {id:this.editForm.id, schoolId: this.editForm.schoolId})
          .then((res) => {
                if (res.code === 0) {
                  this.showUpdate = false;
                  window.location.reload();
                }
              }
          );
    },

    /**
     * 重置密码
     */
    resetPass(){
      if(this.resetPassForm.password!=this.resetPassForm.password2){
        ElMessage.error('两次输入的密码不一致');
        return;
      }
      baseService
          .post("/fii/front/account/resetPwd", {id:this.resetPassForm.id, password: this.resetPassForm.password})
          .then((res) => {
                if (res.code === 0) {
                  this.showResetPass = false
                }
              }
          );
    }


  }
});
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" >
.search-module {
  display: flex;
  justify-content: space-between;
  padding: 0px 20px 0px 20px;
  margin-top: 10px;
  .interval {
    padding: 0px 15px;
  }

  .search-left {
    color: #333333;
    text-align: left;
  }
  .right-btn {
    text-align: right;
  }
}
.global-table {
  margin-top: 15px;
  padding: 0px 20px;
}

.popper-menu {
  border: 0px !important;
  .el-menu {
    padding: 0px !important;
    background-color: #008fd1 !important;
    .el-menu-item-group__title {
      padding: 0px;
    }
    .el-menu-item:hover {
      background-color: #ffffff !important;
      color: #00a0e9;
    }

    .el-menu-item.is-active {
      background-color: #ffffff !important;
    }
  }
}
</style>
